import type { QmsTemplate, QmsTemplateIndex, QmsTemplateMaterial } from "@/pages/qms/template/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //检测模板名称
  templateName?: string;
  //检测种类
  qcTypes?: string;
  //是否启用
  enableFlag?: number;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: QmsTemplate[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/qms/template/pageList",
    data
});
const getInfo = (id: React.Key): Promise<QmsTemplate> =>
  apiClient.get({
    url: `/qms/template/${id}`
});

const add = (data: QmsTemplate): Promise<QmsTemplate> =>
  apiClient.post({
    url: "/qms/template",
    data
});

const update = (data: QmsTemplate): Promise<QmsTemplate> =>
  apiClient.put({
    url: "/qms/template",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/qms/template",
    params: {
    ids: ids.join(",")
  }
});
const gettemplateIndexs = (id: React.Key): Promise<QmsTemplateIndex[]> =>
  apiClient.post({
    url: "/qms/template/index/list",
    data: {
      templateId: id
    }
  });

const gettemplateMaterials = (id: React.Key): Promise<QmsTemplateMaterial[]> =>
  apiClient.post({
    url: "/qms/template/material/list",
    data: {
      templateId: id
    }
  });

export const qmsTemplateService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  gettemplateIndexs,
  gettemplateMaterials,
};

export default qmsTemplateService;